// 标签，栏目，分类，tree 交互 处理
//request before [ [1,2,3 ],[1,2,3] ]   elem cascader value
//response [keyId:val] 分部级别

//就放在第一层的儿子 列表中 回选
export function arrTreeTobj(arr,OldArr,keyId,nodeSub='sub'){
 var newArr =[] //[ [1,2,3 ],[1,2,3] ]
   // arr instanceof Array
   // if(arr instanceof Array){ //[]
   // }else if(arr instanceof Object){
   // }
   const findDepth  =(v,Arr)=>{
     Arr.map((list)=>{
       var depth = list.depth
       if(depth>0){
       newArr[depth -1] = list.keyId
       if(!list.node&&list[nodeSub]){
        // newArr[depth -1] = k
         findDepth(list[nodeSub])
       }else{
         if(list[keyId] !== v){
            newArr=[]
         }
       }
       }else{
         //没有层级
           newArr[0] = v
       }
     })
   }
   for(let i in arr){
     const val = arr[i]
     findDepth(i,OldArr)
   }
  return newArr
}
//
export function findIdToName(val,dataInfo,sub,id,tabName){
console.log('dataInfo',val,dataInfo,sub,id,tabName)
    const arr =[]
    const findIdFn  =(itemVal,dataFilter)=>{
      if(dataFilter instanceof Array){
       dataFilter.map((dataItem)=>{
         if(dataItem[sub]){
            var list = dataItem[sub].filter((items)=>items[id]==itemVal)
            if(list.length>0){
              arr.push(list[0][tabName])
            }else{
              findIdFn(val,dataItem[sub])
            }
         }else{
           var onelist = dataItem[id]==itemVal
           if(onelist){
              arr.push(dataItem[tabName])
           }
         }
       })
        }else{
        }
      }
    val.forEach((item)=>{
     var itemVal = item[item.length - 1]
     findIdFn(itemVal,dataInfo)
    })

  return arr
}

export function arrTreeToArr(arr,tagsId='tagsId',tagsName='tagsName'){
  let newArr = []
    if(arr instanceof Array){
      arr.map((aItem)=>{
        var obj ={}
        if(aItem){
          let aLen = aItem.length
          let keyIdVal = aItem[aLen-1]?aItem[aLen-1]:'';
           let isSelf =  keyIdVal.indexOf('*')>-1 //自定义添加的sadasdasdas
           obj[isSelf?tagsName:tagsId] = isSelf? keyIdVal.split('*')[1]:keyIdVal
           //console.log("sddsdvvvvghhh ",obj)
           newArr.push(obj)
        }


      })

    }
    return newArr
}

export const teacherTarget = [
  {groupEnum:'PRIMARY',itemCode:90002,name:'一级'},//一级
  {groupEnum:'SECONDARY',itemCode:90001,name:'二级'}, //二级
  {groupEnum:'TERTIARY',itemCode:90000,name:'三级'},//三级
  {groupEnum:'SENIOR',itemCode:90003,name:'高级'},//高级
  {groupEnum:'POSITIVE_SENIOR',itemCode:90004,name:'正高级'},//正高级
]
